I have a script that loops through the links in an object. Readers of this forum may remember me from last week. Now I am getting a EXCEPTION_ACCESS_VIOLATION error. The full DXL is below. The error states that line 95 is the culprit (for l in o ->). The script works well for the first module but then fails on some objects in the second module. After the failure I can rerun the script, it will pick up where it left off, but it will get this error again. The script is designed to skip over links whose target module has already been through the script (stored in the completedList). I reviewed the output file and noticed that when I rerun after each failure the first line in the log shows a skipped object. Then no other skipped objects in the log. From what I understand I must be doing something 'right' the first time the script encounters a skip-able object, but I have left something in an untidy state the second time this condition is met. The team here was a great help last time, any ideas for my latest fumbling?
/************************************
TITLE: Link Flip Out Only
DATE: 17 MAR 14
************************************/
Skip completeList = create //List of Modules already reversed
Stream out = write "C:\\temp\\LinkFlipOut_" name(current Project) ".csv"
/************************************
reverse links in linkList
************************************/
void linkFlip(Link l){
Object oSource, oTarget
Module mTarget, mLink
ModName_ mnTarget
string sLinkMod
sLinkMod = fullName(module(l))
mnTarget = module(fullName(target(l)))
mTarget = edit(fullName(mnTarget),false, true, true)
oTarget = target(l)
if (null oTarget) {
mTarget = edit(target(l),false, true, true)
oTarget = target(l)
}
oSource = source(l)
if (null oTarget) {
out << ",NULL\n"
return
}
if (isDeleted(oTarget)) {
out << ",DEL\n"
return
}
if(!canModify(oTarget)){
out <<",!ACCESS\n"
return
}
if (find(completeList, fullName(mnTarget))) {
out << "," fullName(mTarget) "," oTarget."Absolute Number" ",SKIPPED\n"
return
}
if (null mnTarget) {
out << ",NULL mnTarget\n"
return
}
if (null mTarget) {
out << ",NULL mTarget\n"
return
}
out << "," fullName(mnTarget) "," targetAbsNo(l) ""
filtering off
showDeletedObjects on
mLink = edit(fullName(module(l)), false)
oTarget -> sLinkMod -> oSource
if(canDelete(l))
{
delete l
out <<",DELETED\n"
} else {
out << ",FAILED\n"
}
flushDeletions
flush(out)
}
/************************************
Link Search
************************************/
void linkSearch(){
Item iRef
Module m
Link l
Object o
idx = 0
int linkCountOut = 0
int linkCountIn = 0
out <<"Source Mod,Source Object,Target Mod, Target Object,Status\n"
for iRef in current Project do {
if (type(iRef)=="Formal") {
m = edit(fullName(iRef), false, true, true)
if (null m) {
out << "NULL\n"
continue
}
filtering off
showDeletedObjects on
current = m
linkCountOut = 0
linkCountIn = 0
for o in m do {
if (null o) {
out << fullName(m) ",NULL\n"
continue
}
for l in o -> "*" do {
if (null source(l)) {
out << fullName(m) ",NULL\n"
continue
}
if (isDeleted(source(l))) {
out << fullName(m) ",DEL\n"
continue
}
if(!canModify(source(l))){
out << fullName(m) ",!ACCESS\n"
continue
}
out << fullName(m) "," o."Absolute Number" ""
linkFlip(l)
linkCountOut++
}
}
if (!find(completeList, fullName(m))) put(completeList,fullName(m),fullName(m)) //add completed modules to the skip list
save(m)
close(m)
}
}
out << "\n"
flush(out)
}
/************************************
Clean up memory
************************************/
void cleanUp(){
Item iRef
for iRef in current Project do {
if (type(iRef)!="Folder") {
if(open(module(fullName(iRef)))) {
save(module(iRef))
close(module(iRef))
}
}
delete(completeList)
out << "Ending," stringOf(dateAndTime(today)) "\n"
close(out)
flush(out)
}
}
/************************************
MAIN
************************************/
out << "Start," stringOf(dateAndTime(today)) "\n"
out << "Project," name(current Project) "\n"
linkSearch()
cleanUp()
print "Script Complete"
CWicker - Mon Mar 17 15:24:25 EDT 2014 |
Re: Access Violation when retrieving link in object Assuming the error had something to do with the way I was exiting the voids I reworked to code as follows and I have avoided the issue, but I am still not sure what I was doing wrong in the first example. I would appreciate someone helping me to understand what was going on. Now am I encountering null module parameters because I removed several of the null checks I was use before, but they employed the 'return' command which needed to be removed to relieve the access error from above.
/************************************
TITLE: Link Flip Out Only
DATE: 17 MAR 14
************************************/
Skip completeList = create //List of Modules already reversed
Stream out = write "C:\\temp\\LinkFlipOut_" name(current Project) ".csv"
string sOptions[] = {"Yes","No"}
/************************************
Executes link flip
************************************/
void linkFlip(Object oSource, string sLinkMod, Object oTarget, Link l){
out << "," fullName(module(oTarget)) "," oTarget."Absolute Number" ""
mLink = edit(sLinkMod, false)
if (!find(completeList, fullName(module(oTarget)))) {
oTarget -> sLinkMod -> oSource
if(canDelete(l))
{
delete l
out <<",DELETED\n"
} else {
out << ",FAILED\n"
}
}
}
/************************************
prepares links to be flipped
************************************/
void linkPrep(Link l){
Object oSource, oTarget
Module mTarget, mLink
ModName_ mnTarget
string sLinkMod = null
sLinkMod = fullName(module(l))
mnTarget = module(fullName(target(l)))
oTarget = target(l)
if (null oTarget) {
mTarget = edit(target(l),false, true, true)
print "Null Target Opened: " name(mTarget) "\n"
filtering off
graphics off
outlining off
showPictures on
showTables on
sorting off
showDeletedObjects(true)
level(0)
oTarget = target(l)
}
mTarget = edit(fullName(mnTarget),false, true, true)
oSource = source(l)
if (null oTarget) {
out << ",NULL\n"
}
if (isDeleted(oTarget)) {
out << ",DEL\n"
}
if(!canModify(oTarget)){
out <<",!ACCESS\n"
}
if (!null oTarget && !null oSource && !null sLinkMod) {
linkFlip(oSource, sLinkMod, oTarget, l)
}
}
/************************************
Link Search
************************************/
void linkSearch(){
Item iRef
Module m
Link l
Object o
idx = 0
int linkCountOut = 0
int linkCountIn = 0
out <<"Source Mod,Source Object,Target Mod, Target Object,Status\n"
for iRef in current Project do {
if (type(iRef)=="Formal") {
m = edit(fullName(iRef), false, true, true)
if (null m) {
out << "NULL\n"
continue
}
filtering off
graphics off
outlining off
showPictures on
showTables on
sorting off
showDeletedObjects(true)
level(0)
current = m
linkCountOut = 0
linkCountIn = 0
for o in m do {
if (null o) {
out << fullName(m) ",NULL\n"
continue
}
for l in o -> "*" do {
if (null source(l)) {
out << fullName(m) ",NULL\n"
continue
}
if (isDeleted(source(l))) {
out << fullName(m) ",DEL\n"
continue
}
if(!canModify(source(l))){
out << fullName(m) ",!ACCESS\n"
continue
}
out << fullName(m) "," o."Absolute Number" ""
linkPrep(l)
linkCountOut++
}
}
if (!find(completeList, fullName(m))) put(completeList,fullName(m),fullName(m)) //add completed modules to the skip list
flushDeletions
int ans = query(name(m) " \n\nContinue?",sOptions)
if (sOptions[ans] == "No") return
}
}
out << "\n"
flush(out)
}
/************************************
Clean up memory
************************************/
void cleanUp(){
Item iRef
for iRef in current Project do {
if (type(iRef)!="Folder") {
if(open(module(fullName(iRef)))) {
save(module(iRef))
close(module(iRef))
}
}
delete(completeList)
out << "Ending," stringOf(dateAndTime(today)) "\n"
close(out)
flush(out)
}
}
/************************************
MAIN
************************************/
out << "Start," stringOf(dateAndTime(today)) "\n"
out << "Project," name(current Project) "\n"
linkSearch()
cleanUp()
print "Script Complete"
|
Re: Access Violation when retrieving link in object you are trying to put string in the skip (line 120) and for this you have to create the skip list using "createString()". maybe this is an issue? can you iterate using "print" to understand at which statement exception occurres?
Alex. |
Re: Access Violation when retrieving link in object CWicker - Mon Mar 17 17:25:20 EDT 2014 Assuming the error had something to do with the way I was exiting the voids I reworked to code as follows and I have avoided the issue, but I am still not sure what I was doing wrong in the first example. I would appreciate someone helping me to understand what was going on. Now am I encountering null module parameters because I removed several of the null checks I was use before, but they employed the 'return' command which needed to be removed to relieve the access error from above.
/************************************
TITLE: Link Flip Out Only
DATE: 17 MAR 14
************************************/
Skip completeList = create //List of Modules already reversed
Stream out = write "C:\\temp\\LinkFlipOut_" name(current Project) ".csv"
string sOptions[] = {"Yes","No"}
/************************************
Executes link flip
************************************/
void linkFlip(Object oSource, string sLinkMod, Object oTarget, Link l){
out << "," fullName(module(oTarget)) "," oTarget."Absolute Number" ""
mLink = edit(sLinkMod, false)
if (!find(completeList, fullName(module(oTarget)))) {
oTarget -> sLinkMod -> oSource
if(canDelete(l))
{
delete l
out <<",DELETED\n"
} else {
out << ",FAILED\n"
}
}
}
/************************************
prepares links to be flipped
************************************/
void linkPrep(Link l){
Object oSource, oTarget
Module mTarget, mLink
ModName_ mnTarget
string sLinkMod = null
sLinkMod = fullName(module(l))
mnTarget = module(fullName(target(l)))
oTarget = target(l)
if (null oTarget) {
mTarget = edit(target(l),false, true, true)
print "Null Target Opened: " name(mTarget) "\n"
filtering off
graphics off
outlining off
showPictures on
showTables on
sorting off
showDeletedObjects(true)
level(0)
oTarget = target(l)
}
mTarget = edit(fullName(mnTarget),false, true, true)
oSource = source(l)
if (null oTarget) {
out << ",NULL\n"
}
if (isDeleted(oTarget)) {
out << ",DEL\n"
}
if(!canModify(oTarget)){
out <<",!ACCESS\n"
}
if (!null oTarget && !null oSource && !null sLinkMod) {
linkFlip(oSource, sLinkMod, oTarget, l)
}
}
/************************************
Link Search
************************************/
void linkSearch(){
Item iRef
Module m
Link l
Object o
idx = 0
int linkCountOut = 0
int linkCountIn = 0
out <<"Source Mod,Source Object,Target Mod, Target Object,Status\n"
for iRef in current Project do {
if (type(iRef)=="Formal") {
m = edit(fullName(iRef), false, true, true)
if (null m) {
out << "NULL\n"
continue
}
filtering off
graphics off
outlining off
showPictures on
showTables on
sorting off
showDeletedObjects(true)
level(0)
current = m
linkCountOut = 0
linkCountIn = 0
for o in m do {
if (null o) {
out << fullName(m) ",NULL\n"
continue
}
for l in o -> "*" do {
if (null source(l)) {
out << fullName(m) ",NULL\n"
continue
}
if (isDeleted(source(l))) {
out << fullName(m) ",DEL\n"
continue
}
if(!canModify(source(l))){
out << fullName(m) ",!ACCESS\n"
continue
}
out << fullName(m) "," o."Absolute Number" ""
linkPrep(l)
linkCountOut++
}
}
if (!find(completeList, fullName(m))) put(completeList,fullName(m),fullName(m)) //add completed modules to the skip list
flushDeletions
int ans = query(name(m) " \n\nContinue?",sOptions)
if (sOptions[ans] == "No") return
}
}
out << "\n"
flush(out)
}
/************************************
Clean up memory
************************************/
void cleanUp(){
Item iRef
for iRef in current Project do {
if (type(iRef)!="Folder") {
if(open(module(fullName(iRef)))) {
save(module(iRef))
close(module(iRef))
}
}
delete(completeList)
out << "Ending," stringOf(dateAndTime(today)) "\n"
close(out)
flush(out)
}
}
/************************************
MAIN
************************************/
out << "Start," stringOf(dateAndTime(today)) "\n"
out << "Project," name(current Project) "\n"
linkSearch()
cleanUp()
print "Script Complete"
You must not delete a Handle inside the Handle loop. In this case you are deleting a link (line 20) inside the for l in o ->"*" loop (line 102). I'm supposing the delayed "flushDeletions" isn't saving you. A standard method for deleting links is:
In your case perhaps move the actual deleting to the end of the module rather than the end of the object loop. On other news:
-Louie |